package com.restaurant.application.minifacade.data;

import com.google.common.collect.Lists;
import com.nebutown.generation.Convert;
import com.nebutown.generation.PickableBean;

import java.util.List;
import java.util.stream.Collectors;

public class BookingTime implements PickableBean {

    public static final String FN_DATE = "date";
    public static final String FN_TIME = "time";
    public static final String FN_SERVICE = "service";
    
    public static final List<String> FIELD_NAMES = Lists.newArrayList(
            FN_DATE,
            FN_TIME,
            FN_SERVICE);

    private String date;
    private List<String> time;
    private List<String> service;

    public BookingTime(String date, List<String> time, List<String> service) {
        setDate(date);
        setTime(time);
        setService(service);
    }

    public BookingTime() {
    }

    public BookingTime duplicate() {
        BookingTime result = new BookingTime();
        result.date = this.date;
        result.time = this.time == null ? null : this.time.stream().map(e1 -> e1).collect(Collectors.toList());
        result.service = this.service == null ? null : this.service.stream().map(e2 -> e2).collect(Collectors.toList());
        return result;
    }

    @Override
    public String toString() {
        return Convert.toJson(this);
    }

    public String getDate() {
        return date;
    }

    public void setDate(String value) {
        this.date = value;
    }

    public BookingTime withDate(String value) {
        setDate(value);
        return this;
    }

    public BookingTime withDate(String value, String defaultValue) {
        setDate(value == null ? defaultValue : value);
        return this;
    }

    public List<String> getTime() {
        if (time == null) {
            time = Lists.newArrayList();
        }
        return time;
    }

    public void setTime(List<String> value) {
        this.time = value;
    }

    public BookingTime withTime(List<String> value) {
        setTime(value);
        return this;
    }

    public BookingTime withTime(List<String> value, List<String> defaultValue) {
        setTime(value == null ? defaultValue : value);
        return this;
    }

    public BookingTime addTime(String value) {
        if (time == null) {
            time = Lists.newArrayList();
        }
        this.time.add(value);
        return this;
    }

    public List<String> getService() {
        if (service == null) {
            service = Lists.newArrayList();
        }
        return service;
    }

    public void setService(List<String> value) {
        this.service = value;
    }

    public BookingTime withService(List<String> value) {
        setService(value);
        return this;
    }

    public BookingTime withService(List<String> value, List<String> defaultValue) {
        setService(value == null ? defaultValue : value);
        return this;
    }

    public BookingTime addService(String value) {
        if (service == null) {
            service = Lists.newArrayList();
        }
        this.service.add(value);
        return this;
    }
    
    public Object getValueOf(String name) {
        switch (name) {
            case "date":
                return getDate();
            case "time":
                return getTime();
            case "service":
                return getService();
        }
        return null;
    }

    public boolean hasField(String name) {
        return FIELD_NAMES.contains(name);
    }

    @Override
    public int hashCode() {
        return signature().hashCode();
    }

    @Override
    public boolean equals(Object o) {
        if (!(o instanceof BookingTime)) return false;
        return signature().equals(((BookingTime) o).signature());
    }

    public String signature() {
        throw new RuntimeException("Bean BookingTime has no signature defined, no hash code or equals possible.");
    }
}
